﻿@using System.Globalization
@{

    var routeData = ViewContext.RouteData;

    string controller = routeData.GetRequiredString("controller");
    string action = routeData.GetRequiredString("action");
   
    var tRvd = new RouteValueDictionary(ViewContext.RouteData.Values);

    foreach (string key in Request.QueryString.Keys)
    {
        tRvd[key] = Request.QueryString[key].ToString(CultureInfo.InvariantCulture);
    }

    var routeValues = new System.Text.StringBuilder();

    routeValues.Append("{");
    foreach (var t in tRvd)
    {
        if (t.Key != "controller" && t.Key != "action")
        {
            if (Convert.ToString(t.Value).Trim() != string.Empty)
            {
                routeValues.Append(t.Key);
                routeValues.Append(":");
                int intValue;
                if (int.TryParse(t.Value.ToString(), out intValue))
                {
                    routeValues.Append(t.Value);
                }
                else
                {
                    routeValues.Append("'");
                    routeValues.Append(t.Value);
                    routeValues.Append("'");
                }
            }
        }
    }
    routeValues.Append("}");
    routeValues = routeValues.Replace("{}", "");

    SiteMapMVC.SiteMapMvc.GetBreadcrumb(controller, action, routeValues);
    SiteMapMVC.SiteMapMvc.Breadcrumblist.Reverse();
    var count =0;
    foreach (var r in SiteMapMVC.SiteMapMvc.Breadcrumblist)
    {
        @Html.ActionLink(r.Title, r.Action, r.Controller, SiteMapMVC.RouteObj.GetObj(r.RouteValue), new { @class = "removeUnderline" }) 
        if (count < (SiteMapMVC.SiteMapMvc.Breadcrumblist.Count - 1))
        {
    @: >
        }
        count++;
    }
    
}
